package chart.图的存储;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * 边
 *
 * @author yezh
 * @date 2023/7/10 15:32
 */
public class Edge {

    public static List<Edge> init1() {
        Edge e1 = new Edge(0, 1);
        Edge e2 = new Edge(0, 2);
        Edge e4 = new Edge(1, 2);
        Edge e3 = new Edge(1, 3);
        Edge e5 = new Edge(2, 3);
        return Arrays.asList(e1, e2, e3, e4, e5);
    }

    public static List<Edge> graphDFS() {
        Edge e1 = new Edge(0, 1, 2);
        Edge e2 = new Edge(0, 2, 1);
        Edge e3 = new Edge(0, 4, 2);
        Edge e4 = new Edge(1, 2, 4);
        Edge e5 = new Edge(1, 3, 2);
        Edge e6 = new Edge(2, 3, 1);
        Edge e7 = new Edge(2, 4, 1);
        Edge e8 = new Edge(3, 5, 5);
        return Arrays.asList(e1, e2, e3, e4, e5, e6, e7, e8);
    }

    /**
     * 弧尾
     */
    private int arcTail;

    /**
     * 弧头, 有向图中带箭头的那一端
     */
    private int arcHead;

    /**
     * 权值
     */
    private int weigh;

    public Edge(int arcTail, int arcHead) {
        this(arcTail, arcHead, 1);
    }

    public Edge(int arcTail, int arcHead, int weigh) {
        this.arcTail = arcTail;
        this.arcHead = arcHead;
        this.weigh = weigh;
    }

    public int getArcTail() {
        return arcTail;
    }

    public int getArcHead() {
        return arcHead;
    }

    public int getWeigh() {
        return weigh;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Edge edge = (Edge) o;
        return arcTail == edge.arcTail && arcHead == edge.arcHead && weigh == edge.weigh;
    }

    @Override
    public int hashCode() {
        return Objects.hash(arcTail, arcHead, weigh);
    }

}
